<template>
  <view @touchmove.prevent.stop>
    <u-popup overlayOpacity="0.8" style="background:transparent;" :show="isShowRedPacket" border-radius="30"
      mode="center" :safe-area-inset-bottom="false" :closeable="false" @close="isShowRedPacket = false" zIndex="999999">
      <view class=" flex" @touchmove.prevent.stop @click="sendMoneyFn()">
        <image style="width: 500rpx; height: 510rpx;"
          :src="'https://files.meton.vip/ffd08f56c48d3e9f53c5ca0feb586051f069be27532df7ee6a2cd48ff9021c4e.png'">
        </image>
      </view>
    </u-popup>
  </view>
</template>
<script setup lang="ts">
// 红包
import { sendMoney, getListShareRedUser } from '@/addon/shop/api/refund'
import { ref, onMounted } from 'vue';

const isShowRedPacket = ref(false)
const sendMoneyFn = async () => {
  let param = {
    id: redList.value[0].id,
    openId: uni.getStorageSync('openid')
    // openId: 'oBs_o0S53wRJDhZu1XveWQjUIyJI'
  }
  const { data } = await sendMoney(param)
  if (wx.canIUse('requestMerchantTransfer')) {
    wx.requestMerchantTransfer({
      mchId: data.mchid,
      appId: data.appid,
      package: data.package_info,
      success: (res) => {
        // res.err_msg将在页面展示成功后返回应用时返回ok，并不代表付款成功
        console.log('success:', res);
        getListShareRedUserFn()
      },
      fail: (res) => {
        console.log('fail:', res);
      },
      cancel: (res) => {
        console.log('fail:', res);
      },
    });
  } else {
    wx.showModal({
      content: '你的微信版本过低，请更新至最新版本。',
      showCancel: false,
    });
  }
  console.log(data)

}
const redList = ref([])
const getListShareRedUserFn = async () => {
  const { data } = await getListShareRedUser()
  redList.value = data
  if (redList.value && redList.value.length > 0) {
    isShowRedPacket.value = true
  } else {
    isShowRedPacket.value = false

  }
}
onMounted(() => {

  if (uni.getStorageSync(import.meta.env.VITE_REQUEST_STORAGE_TOKEN_KEY)) {

    getListShareRedUserFn()
  }

});
</script>
